package com.niit.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.niit.entity.Student;
import com.niit.mapper.StudentMapper;
import com.niit.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {

    StudentMapper studentMapper;

    @Autowired
    public void setStudentMapper(StudentMapper studentMapper) {
        this.studentMapper = studentMapper;
    }

    @Override
    public Student findOneById(Integer id) {
        return studentMapper.findOneById(id);
    }

    @Override
    public PageInfo<Student> findAllByPage(Student student, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Student> list = studentMapper.findAllByPage(student);
        PageInfo<Student> pageInfo = new PageInfo<Student>(list);
        System.out.println("分页信息："+pageInfo);
        return pageInfo;
    }

    @Override
    public int saveStudent(Student student) {
        int rows = studentMapper.insert(student);
        return rows;
    }

    @Override
    public int updateStudent(Student student) {
        int rows = studentMapper.update(student);
        return rows;
    }

    @Override
    public int deleteStudent(Integer id) {
        int rows = studentMapper.deleteById(id);
        return rows;
    }

}
